﻿using System.Collections.Generic;

namespace 集合副本更改会不会对主数据有影响
{
    internal class Program
    {
        

        static void Main(string[] args)
        {
            object obj = new object();
            List<Student> list = new List<Student>();
            Student student = new Student()
            {
                id = 1,
                age = 1,
                Name = "张三"
            };
            list.Add(student);
            Student student2 = new Student()
            {
                id = 2,
                age = 2,
                Name = "李四"
            };
            list.Add(student2);
            for (int i = 0; i < 100; i++)
            {
                Student student3 = new Student()
                {
                    id = i,
                    age = i,
                    Name = "李四"
                };
                list.Add(student3);
            }
            List<Student> listCopy;
            lock (obj)
            {
                  listCopy = list.ToList();
            }
            Task.Run(() =>
            {
                while (true)
                {
                    foreach (var item in list)
                    {
                        Console.WriteLine(item.age);
                    }
                }
            });
            while (true)
            {
                Student student1 = listCopy.Where(a => a.id == 1).FirstOrDefault();
                student1.age = 20;
                foreach (var item in listCopy)
                {
                    Console.WriteLine(item.age); Console.WriteLine("-------------------");
                }
                Console.WriteLine("-------------------");
            }
           
          
           

            // 计算学时数
            double classHours = (double)totalSeconds / secondsPerClassHour;

            // 保留一位小数且不四舍五入
            double finalClassHours = Math.Floor(classHours * 10) / 10;

           
            Console.ReadLine();
        }
    }

    public class Student
    {
        public int id { get; set; }
        public int age { get; set; }
        public string Name { get; set; }
    }
}